import yaml

from a3mall_zdh.config.config import a3mall_auto
import pytest

def read():
    with open(r'C:\Users\23143\PycharmProjects\Auto_WMS\a3mall_zdh\Data\a3mall.yaml',encoding='utf-8')as f:
        return yaml.safe_load(f)

class Testa3mall():
    token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJhdWQiOltdLCJqdGkiOiJXRUFEMm92Uk50IiwiaWF0IjoxNzYxNzkyMTYyLCJuYmYiOjE3NjE3OTIxNjEsImV4cCI6MTc2MzA4ODE2MiwiaWQiOiJPSHd4TnpZeE56a3lNVFl5ZkdJeU5EZ3pNREppWlRsbE1tUmtNREV5TjJJM00yWXlaVFF6Wm1FNE1HRTIifQ.40fjZkIFxwMwFoFpexR9_okJGP68KCcGZDef4r2zyc4'

    @pytest.fixture()
    def aaa(self):
        a=a3mall_auto(url='http://10.59.9.14:7003/')
        yield a
        a.close()
    @pytest.mark.parametrize('a3mall',read())
    def test_login(self,aaa,a3mall):
        # h={'Cookie':'PHPSESSID=28801ef2572798647f14189a0ac169d9'}

        data={'username':a3mall['username'],
              'password':a3mall['password']
              }
        r1=aaa.post('/api/public/login',data=data)
        print(r1.json())

    def test_01(self,aaa):
        data={'id':'63',
              'type':'regiment',
              'sku_id':'',
              'num':'1',
              'shipping_type':'1'}
        token = Testa3mall.token
        headers={"auth-token":"Bearer "+token}
        r1=aaa.get('api/order/confirm?id=63&type=regiment&sku_id=&num=1&shipping_type=1',data=data,headers=headers)
        print(r1.json())

    def test_02(self,aaa):
        data={"id":"63","type":"regiment","address_id":15,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"wechat","remarks":"","source":1,"url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=63&sku_id=&num=1&type=regiment","sku_id":"","num":"1"}
        token=Testa3mall.token
        headers={"auth-token":"Bearer "+token}
        r1=aaa.post('api/order/create',data=data,headers=headers)
        print(r1.json())

    def test_04(self,aaa):
        data={
            "id":"1662486"
        }
        token=Testa3mall.token
        headers={"auth-token":"Bearer "+token}
        r1=aaa.post('api/order/detail',data=data,headers=headers)
        print(r1.json())

    def test_05(self,aaa):
        h = {'auth-token': 'Bearer ' + Testa3mall.token}
        data={'id':'1676322'}
        r1=aaa.post('api/order/delivery',data=data,headers=h)
        print(r1.json())

    def test_06(self,aaa):
        h = {'auth-token': 'Bearer ' + Testa3mall.token}
        data={'id':'1871','type':'cart','shipping_type':'1'}
        r1=aaa.get('api/order/confirm?id=1871&type=cart&shipping_type=1',data=data,headers=h)
        print(r1.json())

    def test_07(self, aaa):
        h = {'auth-token': 'Bearer ' + Testa3mall.token}
        data = {'id': '1676323'}
        r1 = aaa.post('/api/order/detail', data=data, headers=h)
        print(r1.json())